import React from "react";
import http from "../../../lib/ajax";
import { AppPopupConfirm } from "../../layout/popup";
import Axios from "axios";

function Info() {
  const requsetInsurrance = function() {
    const name = document.getElementsByClassName("input-item name")[0].value.trim();
    const idNumber = document.getElementsByClassName("input-item idNumber")[0].value.trim();
    const cardbank = document.getElementsByClassName("input-item cardbank")[0].value.trim();
    const cardphone = document.getElementsByClassName("input-item cardphone")[0].value.trim();
    // AppPopupConfirm(123123,231,null,212,null);
    if (!name || name.length < 1) {
      AppPopupConfirm("名字过短", "关闭");
      return;
    }
    if (!idNumber || idNumber.length < 14) {
      AppPopupConfirm("身份证不对", "关闭");
      return;
    }
    if (!cardbank || cardbank.length < 10) {
      AppPopupConfirm("银行卡有误", "关闭");
      return;
    }
    if (!cardphone || cardphone.length !== 11) {
      AppPopupConfirm("手机号有误", "关闭");
      return;
    }
    Axios({
      method: "get",
      url: "https://ali-bankcard4.showapi.com/bank3",
      params: {
        acct_name: name,
        acct_pan: cardbank,
        cert_id: idNumber,
        cert_type: "01",
        needBelongArea: true
      },
      headers: {
        Authorization: "APPCODE 9afa1a6c2cd84662a3078ff976bcb6d3"
      }
    })
      .then(d => {
        // console.log(d);
        if (d.data && d.data.showapi_res_body && d.data.showapi_res_body.msg === "认证通过") {
          AppPopupConfirm('身份证，银行卡验证通过','关闭');
          const belong = d.data.showapi_res_body.belong;
          let _data = {
            bankName: belong.bankName,
            encBankNo: belong.cardNum,
            idCard: idNumber,
            insureId: '1126410280384737280',
            mobile: cardphone,
            name: name,
            password: "",
          }
          http("post", "student/createOrder", null, _data, false).then(d => {
            console.log(d);
          });
        } else {
          AppPopupConfirm("验证银行卡失败", "关闭");
        }
      })
      .catch(e => {
        console.warn(e);
        AppPopupConfirm(JSON.stringify(e), "关闭");
      });
    return;
  };
  return (
    <div className="input-body">
      <div className="box">
        <div className="input-block">
          <div className="tag">姓名</div>
          <input type="text" maxLength="8" className="input-item name" />
        </div>
        <div className="input-block">
          <div className="tag">身份证号</div>
          <input type="text" maxLength="18" className="input-item idNumber" />
        </div>
        <div className="input-block">
          <div className="tag">银行卡</div>
          <input type="text" className="input-item cardbank" />
        </div>
        <div className="input-block">
          <div className="tag">学员手机号码</div>
          <input type="text" className="input-item cardphone" />
        </div>
      </div>
      <div className="reg-insurrance">
        <button className="reg-ins-btn" onClick={requsetInsurrance}>
          提交
        </button>
      </div>
    </div>
  );
}

export { Info };
